package cn.dsscm.controller;


import cn.dsscm.pojo.Food;
import cn.dsscm.pojo.User;
import cn.dsscm.service.FoodService;
import cn.dsscm.service.UserService;
import com.alibaba.fastjson.JSONArray;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/food")
public class FoodController {

    @Resource
    private FoodService foodService;

    @RequestMapping(value = "/list",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> list(){
        List<Food> all = foodService.findAll();
        Map<String,Object> map = new HashMap<>();
        if (all == null){
            map.put("msg","失败");
        }else {
            map.put("msg","成功");
            map.put("success",true);
            map.put("data",all);
        }
        return map;
    }


    //菜品详情
    @RequestMapping( value = "/getFood",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> findById(int id){
        Food foods=foodService.findById(id);
        Map<String,Object> map1=new HashMap<>();
        if(foods==null){
            map1.put("msg","失败");
            map1.put("success",false);
        }else {
            map1.put("msg","成功");
            map1.put("success",true);
            map1.put("list",foods);
        }
        return map1;
    }
}
